<template>
	<view class="live-list" :class="config.style">
		<view class="header">
			<text class="title">{{params.title}}</text>
			<!-- <text class="more" @click="goToMoreLink()">查看更多</text> -->
		</view>
		<view class="list" :class="params.rank == 1 ? 'rank1':'rank0'">
			<!--小图-->
			<view :class="params.style == 1 ? 'style1':'style0'" v-if="params.style == 0">
				<view class="item" v-for="(item,index) in params.list" :key="index" @click="goToDetailLink(item.id)">
					<view class="content">
						<view class="cover">
							<image mode="widthFix" :src="item.cover_200" @error="imageError" class="image"></image>
						</view>
						<view class="info">
							<view class="title text-ellipsis-2">{{item.title}}</view>
							<view class="description text-ellipsis" v-if="params.style != 1 && params.rank == 1">{{item.description}}</view>
							<view class="price" :class="!showSale?'hidden':''">￥ {{item.price == 0 ? '免费':item.price}}</view>
							<view class="exp-info">
								<view class="item view">
									<uni-icons type="eye" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_view}}</text>
								</view>
								<view class="item sales">
									<uni-icons type="cart-filled" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
								<view class="item favorites">
									<uni-icons type="star" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!--大图-->
			<view :class="params.style == 1 ? 'style1':'style0'" v-if="params.style == 1">
				<view class="item" v-for="(item,index) in params.list" :key="index" @click="goToDetailLink(item.id)">
					<view class="content">
						<view class="cover">
							<image mode="widthFix" :src="item.cover_400" @error="imageError" class="image"></image>
						</view>
						<view class="info">
							<view class="title text-ellipsis">{{item.title}}</view>
							<view class="description text-ellipsis">{{item.description}}</view>
							<view class="price" :class="!showSale?'hidden':''">￥ {{item.price == 0 ? '免费':item.price}}</view>
							<view class="exp-info">
								<view class="item view">
									<uni-icons type="eye" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.view}}</text>
								</view>
								<view class="item sales">
									<uni-icons type="cart-filled" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.sales}}</text>
								</view>
								<view class="item favorites">
									<uni-icons type="star" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.favorites}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'LiveList',
		props: {
			title: {
				type: String,
				default: '直播课堂列表'
			},
			type: {
				type: String,
				default: 'live_list',
			},
			params: {
				type: Object,
				default: {},
			},
			config: {
				type: Object,
				default: {},
			},
		},
		data() {
			return {
				linkMoreParams: {},
				showSale: this.util.setShowSale(),
			}
		},
		created() {
			//console.log(JSON.stringify(this.params))
			this.getLinkMoreParams();
		},
		methods: {
			/**
			 * IOS小程序判断显示购买价格及按钮
			 */
			setShowSale: function(){
				let systemInfo = uni.getStorageSync('systemInfo');
				this.showSale = true;
				//仅在微信小程序端执行
				// #ifdef MP-WEIXIN
				if(systemInfo.system.search("iOS") != -1){
					this.showSale = false;
					console.log('IOS')
				}
				// #endif
			},
			/**
			 * 获取链接参数
			 */
			getLinkMoreParams: function(){
				let linkMoreParams = {
					category_id : this.params.category_id,
					order_field : this.params.order_field,
					order_type: this.params.order_type,
				}
				//console.log(linkParams);
				this.linkMoreParams = linkMoreParams
			},
			/**
			 * 路由至页面
			 */
			goToMoreLink: function(){
				let params = this.linkMoreParams
				let urlParams = this.util.urlEncode(params)
				let url = '../live/lists?' + urlParams
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
			goToDetailLink: function(id){
				let urlParams = 'id='+id
				let url = '../live/detail?' + urlParams
				//console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
		}
	}
</script>

<style lang="scss">
	.live-list {
		margin: 5px;
		.header {
			display: flex;
			justify-content: space-between;
			padding: 10rpx;
			margin: 10rpx 0 0 0;
			.title {
				flex: 1;
				font-size: 32rpx;
				font-weight: 600;
				color: #000;
			}
			.more {
				color: #999;
				font-size: 24rpx;
				line-height: 44rpx;
			}
		}
		/*横排*/
			.list.rank0 {
				
				/*小图*/
				.style0{
					display: flex;
					flex-wrap: wrap;
					.item {
						box-sizing:border-box;
						width: 50%;
						padding: 10rpx;
						.content {
							background-color: #fff;
							.cover {
								border-radius: 10rpx;
								overflow: hidden;
								.image {
									width: 100%;
									height: auto;
									display: block;
								}
							}
							.info {
								padding: 10rpx;
								.title {
									margin-top: 16rpx;
									font-size: 28rpx;
									color: #000;
									font-weight: 600;
									height: 72rpx;
									line-height: 36rpx;
								}
								.description {
									color: #999;
									font-size: 24rpx;
								}
								.price {
									margin-top: 10rpx;
									font-size: 24rpx;
								}
								.exp-info {
									margin-top: 10rpx;
									color: #999;
									font-size: 24rpx;
									.item {
										display: inline;
										.num {
											margin: 0 10rpx;
										}
									}
								}
							}
						}
					}
				}
			}
			/*竖排*/
			.list.rank1 {
				/*小图*/
				.style0{
					display: flex;
					flex-wrap: wrap;
					.item {
						width: 100%;
						.content {
							padding: 10rpx;
							display: flex;
							flex-wrap: wrap;
							.cover {
								width: 280rpx;
								border-radius: 10rpx;
								overflow: hidden;
								.image {
									width: 100%;
									height: auto;
									display: block;
								}
							}
							.info {
								padding-left: 20rpx;
								flex: 1;
								.title {
									font-size: 28rpx;
									color: #000;
									font-weight: 600;
									height: 72rpx;
									line-height: 36rpx;
								}
								.description {
									color: #999;
									font-size: 24rpx;
								}
								.price {
									margin-top: 10rpx;
									font-size: 24rpx;
								}
								.exp-info {
									margin-top: 10rpx;
									color: #999;
									font-size: 24rpx;
									.item {
										display: inline;
										.num {
											margin: 0 10rpx;
										}
									}
								}
							}
						}
					}
				}
				
				/*大图*/
				.style1{
					display: flex;
					flex-wrap: wrap;
					.item {
						width: 100%;
						.content {
							position: relative;
							min-height: 180rpx;
							margin: 0 10rpx 20rpx 10rpx;
							margin-bottom: 30rpx;
							box-shadow: 0 0 20rpx rgba(0,0,0,.12);
							border-radius: 10rpx;
							overflow: hidden;
							.cover {
								width: 100%;
								border-radius: 10rpx;
								overflow: hidden;
								.image {
									width: 100%;
									display: block;
								}
							}
							.info {
								position: absolute;
								left: 0;
								right: 0;
								bottom: 0;
								padding: 20rpx;
								background-color: rgba(255,255,255,0.8);
								.title {
									font-size: 30rpx;
									color: #000;
									font-weight: 600;
									line-height: 36rpx;
								}
								.description {
									margin-top: 10rpx;
									color: #4d4545;
									font-size: 28rpx;
								}
								.price {
									margin-top: 10rpx;
									font-size: 24rpx;
								}
								.exp-info {
									margin-top: 10rpx;
									color: #999;
									font-size: 24rpx;
									.item {
										display: inline;
										.num {
											margin: 0 10rpx;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	
	/*页面风格设计*/
	.Blue {
		.price {
			color: $Blue;
		}
	}
	.Green {
		.price {
			color: $Green;
		}
	}
	.LightRed {
		.price {
			color: $LightRed;
		}
	}
	.Orange {
		.price {
			color: $Orange;
		}
	}
	.LightPink {
		.price {
			color: $LightPink;
		}
	}
	.Magenta {
		.price {
			color: $Magenta;
		}
	}
</style>
